# == Schema Information
#
# Table name: brands
#
#  id         :integer          not null, primary key
#  title      :string
#  status     :integer          default(0)
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  channel_id :integer
#

class Brand < ApplicationRecord

  validates :title, presence: { message: "标题不能为空" }

  belongs_to :channel

  delegate :name, to: :channel, prefix: :channel

  before_create :set_default_channel_id

  private

  def set_default_channel_id
    self.channel_id = Channel.first.id if self.channel_id.nil?
  end

end
